
/** vfork*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main(int argc,char ** argv)
{
	int cnt=1;
	switch(vfork()){
		case -1:
			perror("fork error");
			return 1;
		case 0:
			cnt=10;
			printf("cnt:%d\n",cnt);
			printf("i am child process,pid:%d,getpgrp:%d\n",getpid(),getpgrp());
			printf("i am child process,pid:%d,getpgrp:%d\n",getpid(),getpgid(0));
			//setpgrp();
			if(-1==setpgid(0,0))
				perror("setpgid error");
			printf("PGID=%d\n",getpgrp());
			printf("sid:%d\n",getsid(0));
			_exit(0);
		default:
			printf("i am parent process,pid:%d,getpgrp:%d\n",getpid(),getpgrp());
			printf("i am pparent rocess,pid:%d,getpgrp:%d\n",getpid(),getpgid(0));
			printf("cnt:%d\n",cnt);
			printf("sid:%d\n",getsid(0));
	}
	while(1)
		printf("hello world\n");
	return 0;
}
